 /*
 * @description: 收入统计-任务收益
 * @Author: along
 * @Date: 2021-06-05
 * @Last Modified by: along
 * @Last Modified time: 2021-06-05
 */
<template>
    <div class="container studentCommissionThrid">

        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">任务名称</p>
                    <el-input
                        v-model="formData.keyword"
                        placeholder="请输入任务名称"
                        size="medium"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
            </div>
            <div class="header-right">
                <div class="header-new-box">
                    <p class="__info_title">
                        所得任务收益统计：
                        <span>
                            ¥{{ offline_task_total_income ? offline_task_total_income.toFixed(2) : '0.00' }}
                        </span>
                    </p>
                    <el-button
                        size="medium"
                        type="primary"
                        :style="{width: '128px', marginLeft: '32px'}"
                        @click="$refs.thridDialog.show('add')"
                    >
                        添加信息
                    </el-button>
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="studentCommissionThrid"
        >
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="task_category"
                label="任务类型"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.task_category }}
                </template>
            </el-table-column>
            <el-table-column
                prop="task_title"
                label="任务名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="task_accept_time"
                label="任务领取时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.task_accept_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="award_time"
                label="实际到账时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.award_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                </template>
            </el-table-column>
            <el-table-column
                prop="award_money"
                label="任务奖励"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    ¥{{ scope.row.award_money ? scope.row.award_money : '0.00' }}
                </template>
            </el-table-column>
            <el-table-column
                prop=""
                label="实际获得金额"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    ¥{{ scope.row.award_money_act ? scope.row.award_money_act : '0.00' }}
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
            >
                <!-- 手动添加有这个操作 -->
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        class="curse-add"
                        @click="handleEditData(scope.row)"
                    >
                        修改
                    </el-button>
                    <el-button
                        type="text"
                        class="curse-add"
                        :style="{color: 'rgba(249, 91, 86, 1)'}"
                        @click="handleDeleteData(scope.row)"
                    >
                        删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <!-- <div class="pagination-wrapper clearfix">
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div> -->

        <!-- 添加编辑信息 -->
        <thrid-dialog
            ref="thridDialog"
            @emit="handleGetList"
        />
    </div>
</template>

<script>
import thridDialog from '@/components/student/student-thrid-dialog.vue';
import { back } from '@/mixin/back';
export default {
    mixins: [back],
    components: {
        thridDialog
    },
    props: {
        agent_no: {
            type: String,
            default: ''
        },
        offline_task_total_income: {
            type: Number,
            default: 0
        },
        start_time: {
            type: Number,
            default: 0
        },
        end_time: {
            type: Number,
            default: 0
        }
    },
    data () {
        return {
            ID: '',
            formData: {
                keyword: ''
            },
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {}
        };
    },
    filters: {
        filterType (val) {
            if(val === 1) return '精英任务';
            if(val === 2) return '远程任务';
            if(val === 3) return '精英基础任务';
        }
    },
    computed: {},
    watch: {
        start_time (val) {
            this.getTableData();
        },
        end_time (val) {
            this.getTableData();
        }
    },
    mounted () {
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },
    methods: {
        /**
         * @description 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/stuagent_rebate_task%5Cget_list', {
                page_id: page || this.page.now_page,
                task_title: this.formData.keyword,
                agent_no: this.agent_no,
                start_time: this.start_time,
                end_time: this.end_time
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data;
                    // this.page.now_page = resp.data.page.now_page;
                    // this.page.total_count = resp.data.page.total_count;
                    // this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        /**
         * @description 编辑信息
         */
        handleEditData (row) {
            this.ID = row.id;
            this.$refs.thridDialog.show('edit', [{
                task_type: row.task_category,//任务类型
                task_title: row.task_title,//任务名称
                task_award_money: row.award_money,//任务奖励
                task_actual_money: row.award_money_act,//实际获得金额
                task_time: row.task_accept_time * 1000,//任务领取时间
                task_award_time: row.award_time * 1000//奖金到账时间
            }]);
        },

        /**
         * @description 删除
         */
        handleDeleteData (row) {
            this.$confirm('是否要删除当前数据?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/stuagent_rebate_task%5Cdelete', {
                    id: row.id
                }, resp => {
                    if (resp.code === 1) {
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            message: '操作成功',
                            type: 'success',
                            duration: 2000
                        });
                    } else {
                        this.$notify({
                            title: '失败',
                            message: resp.msg,
                            duration: 2000,
                            type: 'warning'
                        });
                    }
                });
            });
        },

        /**
         * @description 确认添加信息
         */
        handleGetList (row) {

            const {task_type, task_title, task_award_money,task_actual_money, task_time, task_award_time } = row.list[0];

            const data = {
                id: row.type == 'add' ? '' : this.ID,
                agent_no: this.agent_no,
                task_category: task_type,
                task_title: task_title,
                task_accept_time: parseInt(new Date(task_time).getTime() / 1000),
                award_time: parseInt(new Date( task_award_time).getTime() / 1000),
                award_money: task_award_money,
                award_money_act: task_actual_money
            };

            this.$post('/student/stuagent_rebate_task%5Csave', {
                ...data
            }, resp => {
                if (resp.code === 1) {
                    this.getTableData();
                    this.$notify({
                        title: '提示',
                        message: '操作成功',
                        type: 'success',
                        duration: 2000
                    });
                } else {
                    this.$notify({
                        title: '失败',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 24px 32px 12px 32px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 24px;
                white-space: nowrap;
                &-title {
                    margin-right: 12px;
                    white-space: nowrap;
                }
                .__info_title {
                    display: flex;
                    align-items: center;
                    color: rgba(51, 51, 51, 1);
                    font-size: 14px;
                    span {
                        color: rgba(255, 142, 57, 1);
                        font-weight: 500;
                        font-size: 14px;
                    }
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }

    .__zsdx_wrap {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        .__top {
            display: flex;
            align-items: center;
            .__top_name {
                color: rgba(51, 51, 51, 1);
                font-size: 14px;
                font-weight: 500;
                margin-right: 6px;
            }
            .__top_logo {
                width: 28px;
                height: 14px;
            }
        }
        .__phone {
            height: 20px;
            color: rgba(153, 153, 153, 1);
            font-size: 14px;
            line-height: 20px;
            margin-top: 7px;
            margin-bottom: 5px;
        }
        .__id {
            height: 20px;
            color: rgba(153, 153, 153, 1);
            font-size: 14px;
            line-height: 20px;
        }
    }

    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
</style>
<style lang="less">
    .studentCommissionThrid{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
    }
</style>
